/*
 * Copyright (C) 2015 Zhang Rui <bbcallen@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * https://github.com/Bilibili/jni4android
 * This file is automatically generated by jni4android, do not modify.
 */

#include "Codec.h"


typedef struct J4AC_ohos_media_codec_Codec__ICodecListener {
    jclass id;

    jmethodID method_onReadBuffer;
    jmethodID method_onError;
} J4AC_ohos_media_codec_Codec__ICodecListener;
static J4AC_ohos_media_codec_Codec__ICodecListener class_J4AC_ohos_media_codec_Codec__ICodecListener;

typedef struct J4AC_ohos_media_codec_Codec {
    jclass id;

    jmethodID method_createDecoder;
    jmethodID method_setVideoSurface;
    jmethodID method_setCodecFormat;
    jmethodID method_registerCodecListener;
    jmethodID method_getBufferFormat;
    jmethodID method_writeBuffer;
    jmethodID method_getAvailableBuffer;
    jmethodID method_start;
    jmethodID method_stop;
    jmethodID method_release;
} J4AC_ohos_media_codec_Codec;
static J4AC_ohos_media_codec_Codec class_J4AC_ohos_media_codec_Codec;

jobject J4AC_ohos_media_codec_Codec__createDecoder(JNIEnv *env)
{
    return (*env)->CallStaticObjectMethod(env, class_J4AC_ohos_media_codec_Codec.id, class_J4AC_ohos_media_codec_Codec.method_createDecoder);
}

jobject J4AC_ohos_media_codec_Codec__createDecoder__catchAll(JNIEnv *env)
{
    jobject ret_object = J4AC_ohos_media_codec_Codec__createDecoder(env);
    if (J4A_ExceptionCheck__catchAll(env) || !ret_object) {
        return NULL;
    }

    return ret_object;
}

jobject J4AC_ohos_media_codec_Codec__createDecoder__asGlobalRef__catchAll(JNIEnv *env)
{
    jobject ret_object   = NULL;
    jobject local_object = J4AC_ohos_media_codec_Codec__createDecoder__catchAll(env);
    if (J4A_ExceptionCheck__catchAll(env) || !local_object) {
        ret_object = NULL;
        goto fail;
    }

    ret_object = J4A_NewGlobalRef__catchAll(env, local_object);
    if (!ret_object) {
        ret_object = NULL;
        goto fail;
    }

fail:
    J4A_DeleteLocalRef__p(env, &local_object);
    return ret_object;
}

jboolean J4AC_ohos_media_codec_Codec__setVideoSurface(JNIEnv *env, jobject thiz, jobject surface)
{
    if( class_J4AC_ohos_media_codec_Codec.method_setVideoSurface==NULL){

    }else{

    }

    if(surface==NULL){

    }else{

    }

    return (*env)->CallBooleanMethod(env, thiz, class_J4AC_ohos_media_codec_Codec.method_setVideoSurface, surface);
}

jboolean J4AC_ohos_media_codec_Codec__setVideoSurface__catchAll(JNIEnv *env, jobject thiz, jobject surface)
{
    jboolean retValue=J4AC_ohos_media_codec_Codec__setVideoSurface(env, thiz, surface);

    if (J4A_ExceptionCheck__catchAll(env)) {
        return false;
    }

    return retValue;
}

jboolean J4AC_ohos_media_codec_Codec__setCodecFormat(JNIEnv *env, jobject thiz, jobject format)
{
   return  (*env)->CallBooleanMethod(env, thiz, class_J4AC_ohos_media_codec_Codec.method_setCodecFormat, format);
}

jboolean J4AC_ohos_media_codec_Codec__setCodecFormat__catchAll(JNIEnv *env, jobject thiz, jobject format)
{
    jboolean ret_value = J4AC_ohos_media_codec_Codec__setCodecFormat(env, thiz, format);
    if (J4A_ExceptionCheck__catchAll(env)) {
        return false;
    }
    return ret_value;
}

jboolean J4AC_ohos_media_codec_Codec__registerCodecListener(JNIEnv *env, jobject thiz, jobject listener)
{
    return (*env)->CallBooleanMethod(env, thiz, class_J4AC_ohos_media_codec_Codec.method_registerCodecListener, listener);
}

jboolean J4AC_ohos_media_codec_Codec__registerCodecListener__catchAll(JNIEnv *env, jobject thiz, jobject listener)
{
    jboolean ret_value = J4AC_ohos_media_codec_Codec__registerCodecListener(env, thiz, listener);
    if (J4A_ExceptionCheck__catchAll(env)) {
        return false;
    }

    return ret_value;
}

void J4AC_ohos_media_codec_Codec__ICodecListener__onReadBuffer(JNIEnv *env, jobject thiz, jobject var1, jobject var2, jint var3)
{
    (*env)->CallVoidMethod(env, thiz, class_J4AC_ohos_media_codec_Codec__ICodecListener.method_onReadBuffer, var1, var2, var3);
}

void J4AC_ohos_media_codec_Codec__ICodecListener__onReadBuffer__catchAll(JNIEnv *env, jobject thiz, jobject var1, jobject var2, jint var3)
{
    J4AC_ohos_media_codec_Codec__ICodecListener__onReadBuffer(env, thiz, var1, var2, var3);
    J4A_ExceptionCheck__catchAll(env);
}

void J4AC_ohos_media_codec_Codec__ICodecListener__onError(JNIEnv *env, jobject thiz, jint var1, jint var2, jint var3)
{
    (*env)->CallVoidMethod(env, thiz, class_J4AC_ohos_media_codec_Codec__ICodecListener.method_onError, var1, var2, var3);
}

void J4AC_ohos_media_codec_Codec__ICodecListener__onError__catchAll(JNIEnv *env, jobject thiz, jint var1, jint var2, jint var3)
{
    J4AC_ohos_media_codec_Codec__ICodecListener__onError(env, thiz, var1, var2, var3);
    J4A_ExceptionCheck__catchAll(env);
}

int J4A_loadClass__J4AC_ohos_media_codec_Codec__ICodecListener(JNIEnv *env)
{
    int         ret                   = -1;
    const char *J4A_UNUSED(name)      = NULL;
    const char *J4A_UNUSED(sign)      = NULL;
    jclass      J4A_UNUSED(class_id)  = NULL;
    int         J4A_UNUSED(api_level) = 0;

    if (class_J4AC_ohos_media_codec_Codec__ICodecListener.id != NULL)
        return 0;

    sign = "ohos/media/codec/Codec$ICodecListener";
    class_J4AC_ohos_media_codec_Codec__ICodecListener.id = J4A_FindClass__asGlobalRef__catchAll(env, sign);
    if (class_J4AC_ohos_media_codec_Codec__ICodecListener.id == NULL)
        goto fail;

    class_id = class_J4AC_ohos_media_codec_Codec__ICodecListener.id;
    name     = "onReadBuffer";
    sign     = "(Ljava/nio/ByteBuffer;Lohos/media/common/BufferInfo;I)V";
    class_J4AC_ohos_media_codec_Codec__ICodecListener.method_onReadBuffer = J4A_GetMethodID__catchAll(env, class_id, name, sign);
    if (class_J4AC_ohos_media_codec_Codec__ICodecListener.method_onReadBuffer == NULL)
        goto fail;

    class_id = class_J4AC_ohos_media_codec_Codec__ICodecListener.id;
    name     = "onError";
    sign     = "(III)V";
    class_J4AC_ohos_media_codec_Codec__ICodecListener.method_onError = J4A_GetMethodID__catchAll(env, class_id, name, sign);
    if (class_J4AC_ohos_media_codec_Codec__ICodecListener.method_onError == NULL)
        goto fail;

    J4A_ALOGD("J4ALoader: OK: '%s' loaded\n", "ohos.media.codec.Codec$ICodecListener");
    ret = 0;
fail:
    return ret;
}

jobject J4AC_ohos_media_codec_Codec__getBufferFormat(JNIEnv *env, jobject thiz, jobject buffer)
{
    return (*env)->CallObjectMethod(env, thiz, class_J4AC_ohos_media_codec_Codec.method_getBufferFormat, buffer);
}

jobject J4AC_ohos_media_codec_Codec__getBufferFormat__catchAll(JNIEnv *env, jobject thiz, jobject buffer)
{
    jobject ret_object = J4AC_ohos_media_codec_Codec__getBufferFormat(env, thiz, buffer);
    if (J4A_ExceptionCheck__catchAll(env) || !ret_object) {
        return NULL;
    }

    return ret_object;
}

jobject J4AC_ohos_media_codec_Codec__getBufferFormat__asGlobalRef__catchAll(JNIEnv *env, jobject thiz, jobject buffer)
{
    jobject ret_object   = NULL;
    jobject local_object = J4AC_ohos_media_codec_Codec__getBufferFormat__catchAll(env, thiz, buffer);
    if (J4A_ExceptionCheck__catchAll(env) || !local_object) {
        ret_object = NULL;
        goto fail;
    }

    ret_object = J4A_NewGlobalRef__catchAll(env, local_object);
    if (!ret_object) {
        ret_object = NULL;
        goto fail;
    }

fail:
    J4A_DeleteLocalRef__p(env, &local_object);
    return ret_object;
}

jboolean J4AC_ohos_media_codec_Codec__writeBuffer(JNIEnv *env, jobject thiz, jobject buffer, jobject info)
{
    return (*env)->CallBooleanMethod(env, thiz, class_J4AC_ohos_media_codec_Codec.method_writeBuffer, buffer, info);
}

jboolean J4AC_ohos_media_codec_Codec__writeBuffer__catchAll(JNIEnv *env, jobject thiz, jobject buffer, jobject info)
{
    jboolean ret_value = J4AC_ohos_media_codec_Codec__writeBuffer(env, thiz, buffer, info);
    if (J4A_ExceptionCheck__catchAll(env)) {
        return false;
    }

    return ret_value;
}

jobject J4AC_ohos_media_codec_Codec__getAvailableBuffer(JNIEnv *env, jobject thiz, jlong timeout)
{
    return (*env)->CallObjectMethod(env, thiz, class_J4AC_ohos_media_codec_Codec.method_getAvailableBuffer, timeout);
}

jobject J4AC_ohos_media_codec_Codec__getAvailableBuffer__catchAll(JNIEnv *env, jobject thiz, jlong timeout)
{
    jobject ret_object = J4AC_ohos_media_codec_Codec__getAvailableBuffer(env, thiz, timeout);
    if (J4A_ExceptionCheck__catchAll(env) || !ret_object) {
        return NULL;
    }

    return ret_object;
}

jobject J4AC_ohos_media_codec_Codec__getAvailableBuffer__asGlobalRef__catchAll(JNIEnv *env, jobject thiz, jlong timeout)
{
    jobject ret_object   = NULL;
    jobject local_object = J4AC_ohos_media_codec_Codec__getAvailableBuffer__catchAll(env, thiz, timeout);
    if (J4A_ExceptionCheck__catchAll(env) || !local_object) {
        ret_object = NULL;
        goto fail;
    }

    ret_object = J4A_NewGlobalRef__catchAll(env, local_object);
    if (!ret_object) {
        ret_object = NULL;
        goto fail;
    }

fail:
    J4A_DeleteLocalRef__p(env, &local_object);
    return ret_object;
}

jboolean J4AC_ohos_media_codec_Codec__start(JNIEnv *env, jobject thiz)
{
    return (*env)->CallBooleanMethod(env, thiz, class_J4AC_ohos_media_codec_Codec.method_start);
}

jboolean J4AC_ohos_media_codec_Codec__start__catchAll(JNIEnv *env, jobject thiz)
{
    jboolean ret_value = J4AC_ohos_media_codec_Codec__start(env, thiz);
    if (J4A_ExceptionCheck__catchAll(env)) {
        return false;
    }

    return ret_value;
}

jboolean J4AC_ohos_media_codec_Codec__stop(JNIEnv *env, jobject thiz)
{
    return (*env)->CallBooleanMethod(env, thiz, class_J4AC_ohos_media_codec_Codec.method_stop);
}

jboolean J4AC_ohos_media_codec_Codec__stop__catchAll(JNIEnv *env, jobject thiz)
{
    jboolean ret_value = J4AC_ohos_media_codec_Codec__stop(env, thiz);
    if (J4A_ExceptionCheck__catchAll(env)) {
        return false;
    }

    return ret_value;
}

jboolean J4AC_ohos_media_codec_Codec__release(JNIEnv *env, jobject thiz)
{
    return (*env)->CallBooleanMethod(env, thiz, class_J4AC_ohos_media_codec_Codec.method_release);
}

jboolean J4AC_ohos_media_codec_Codec__release__catchAll(JNIEnv *env, jobject thiz)
{
    jboolean ret_value = J4AC_ohos_media_codec_Codec__release(env, thiz);
    if (J4A_ExceptionCheck__catchAll(env)) {
        return false;
    }

    return ret_value;
}

int J4A_loadClass__J4AC_ohos_media_codec_Codec(JNIEnv *env)
{

    int         ret                   = -1;
    const char *J4A_UNUSED(name)      = NULL;
    const char *J4A_UNUSED(sign)      = NULL;
    jclass      J4A_UNUSED(class_id)  = NULL;
    int         J4A_UNUSED(api_level) = 0;

    if (class_J4AC_ohos_media_codec_Codec.id != NULL)
        return 0;


    sign = "ohos/media/codec/Codec";
    class_J4AC_ohos_media_codec_Codec.id = J4A_FindClass__asGlobalRef__catchAll(env, sign);
    if (class_J4AC_ohos_media_codec_Codec.id == NULL)
        goto fail;


    class_id = class_J4AC_ohos_media_codec_Codec.id;
    name     = "createDecoder";
    sign     = "()Lohos/media/codec/Codec;";
    class_J4AC_ohos_media_codec_Codec.method_createDecoder = J4A_GetStaticMethodID__catchAll(env, class_id, name, sign);
    if (class_J4AC_ohos_media_codec_Codec.method_createDecoder == NULL)
        goto fail;


    class_id = class_J4AC_ohos_media_codec_Codec.id;
    name     = "setVideoSurface";
    sign     = "(Lohos/agp/graphics/Surface;)Z";
    class_J4AC_ohos_media_codec_Codec.method_setVideoSurface = J4A_GetMethodID__catchAll(env, class_id, name, sign);
    if (class_J4AC_ohos_media_codec_Codec.method_setVideoSurface == NULL)
        goto fail;


    class_id = class_J4AC_ohos_media_codec_Codec.id;
    name     = "setCodecFormat";
    sign     = "(Lohos/media/common/Format;)Z";
    class_J4AC_ohos_media_codec_Codec.method_setCodecFormat = J4A_GetMethodID__catchAll(env, class_id, name, sign);
    if (class_J4AC_ohos_media_codec_Codec.method_setCodecFormat == NULL)
        goto fail;


    class_id = class_J4AC_ohos_media_codec_Codec.id;
    name     = "registerCodecListener";
    sign     = "(Lohos/media/codec/Codec$ICodecListener;)Z";
    class_J4AC_ohos_media_codec_Codec.method_registerCodecListener = J4A_GetMethodID__catchAll(env, class_id, name, sign);
    if (class_J4AC_ohos_media_codec_Codec.method_registerCodecListener == NULL)
        goto fail;

    ret = J4A_loadClass__J4AC_ohos_media_codec_Codec__ICodecListener(env);
    if (ret)
        goto fail;

    class_id = class_J4AC_ohos_media_codec_Codec.id;
    name     = "getBufferFormat";
    sign     = "(Ljava/nio/ByteBuffer;)Lohos/media/common/Format;";
    class_J4AC_ohos_media_codec_Codec.method_getBufferFormat = J4A_GetMethodID__catchAll(env, class_id, name, sign);
    if (class_J4AC_ohos_media_codec_Codec.method_getBufferFormat == NULL)
        goto fail;

    class_id = class_J4AC_ohos_media_codec_Codec.id;
    name     = "writeBuffer";
    sign     = "(Ljava/nio/ByteBuffer;Lohos/media/common/BufferInfo;)Z";
    class_J4AC_ohos_media_codec_Codec.method_writeBuffer = J4A_GetMethodID__catchAll(env, class_id, name, sign);
    if (class_J4AC_ohos_media_codec_Codec.method_writeBuffer == NULL)
        goto fail;

    class_id = class_J4AC_ohos_media_codec_Codec.id;
    name     = "getAvailableBuffer";
    sign     = "(J)Ljava/nio/ByteBuffer;";
    class_J4AC_ohos_media_codec_Codec.method_getAvailableBuffer = J4A_GetMethodID__catchAll(env, class_id, name, sign);
    if (class_J4AC_ohos_media_codec_Codec.method_getAvailableBuffer == NULL)
        goto fail;

    class_id = class_J4AC_ohos_media_codec_Codec.id;
    name     = "start";
    sign     = "()Z";
    class_J4AC_ohos_media_codec_Codec.method_start = J4A_GetMethodID__catchAll(env, class_id, name, sign);
    if (class_J4AC_ohos_media_codec_Codec.method_start == NULL)
        goto fail;

    class_id = class_J4AC_ohos_media_codec_Codec.id;
    name     = "stop";
    sign     = "()Z";
    class_J4AC_ohos_media_codec_Codec.method_stop = J4A_GetMethodID__catchAll(env, class_id, name, sign);
    if (class_J4AC_ohos_media_codec_Codec.method_stop == NULL)
        goto fail;

    class_id = class_J4AC_ohos_media_codec_Codec.id;
    name     = "release";
    sign     = "()Z";
    class_J4AC_ohos_media_codec_Codec.method_release = J4A_GetMethodID__catchAll(env, class_id, name, sign);
    if (class_J4AC_ohos_media_codec_Codec.method_release == NULL)
        goto fail;


    J4A_ALOGD("J4ALoader: OK: '%s' loaded\n", "ohos.media.codec.Codec");
    ret = 0;
fail:

    return ret;
}
